package it.polimi.traveldream.entity;

import it.polimi.traveldream.dto.AccomodationDTO;

import java.io.Serializable;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

/**
 * The persistent class for the accomodation database table.
 * 
 */
@Entity
@Table(name = "accomodation")
@DiscriminatorValue("accomodation")
@NamedQueries({
		@NamedQuery(name = Accomodation.FIND_ALL, query = "SELECT a FROM Accomodation a WHERE a.valid = true"),
		@NamedQuery(name = Accomodation.FIND_FOR_CITY, query = "SELECT a FROM Accomodation a WHERE a.city = :city AND a.valid = true") })
public class Accomodation extends Product implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_ALL = "Accomodation.findAll";

	public static final String FIND_FOR_CITY = "Accomodation.findForCity";

	public enum Type {
		HOTEL;
	}

	@NotEmpty
	private String city;

	@NotNull
	@Enumerated(EnumType.STRING)
	private Type type;

	public Accomodation() {
	}

	public Accomodation(AccomodationDTO accomodation) {
		super(accomodation);
		this.setCity(accomodation.getCity());
		this.setType(accomodation.getType());
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Type getType() {
		return this.type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public void setType(String type) {
		this.setType(Type.valueOf(type));
	}

	@Override
	public AccomodationDTO convertToDTO() {
		AccomodationDTO accomodation = new AccomodationDTO();
		accomodation.setCity(this.getCity());
		accomodation.setDescription(this.getDescription());
		accomodation.setId(this.getId());
		accomodation.setName(this.getName());
		accomodation.setPrice(this.getPrice());
		accomodation.setType(this.getType().toString());
		accomodation.setValid(this.getValid());
		return accomodation;
	}

}